package com.sky.controller.admin;


import com.sky.result.Result;
import com.sky.utils.AliOssUtil;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@Slf4j
@RequestMapping("/admin/common")
@Api("通用接口")
public class CommonController {

    @Autowired
    AliOssUtil aliOssUtil;
    @PostMapping("/upload")
    public Result<String> uploadPicture(MultipartFile file) throws IOException {
        log.info("文件上传{}",file);
        String fileName = aliOssUtil.upload(file);
//        System.out.println(fileName);
       /* String originalFilename = image.getOriginalFilename();
        int index = originalFilename.lastIndexOf(".");
        String substring = originalFilename.substring(index);
        String fileName = UUID.randomUUID() +substring;
        System.out.println(fileName);
//        image.transferTo(new File("D:\\itheima\\project\\tlias\\src\\main\\resources\\pictures"+fileName));
        image.transferTo(new File("D:\\itheima\\project\\tlias\\src\\main\\resources\\pictures\\"+fileName));*/
        return Result.success(fileName);
    }
}
